package com.tjtt.tdm.codeReview.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.codehaus.groovy.runtime.NullObject;
import org.ietf.jgss.Oid;

import com.opensymphony.xwork2.ActionContext;
import com.tjtt.gwm.bean.Gongyingshang;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.base.StringUtil;
import com.tjtt.tdm.codeReview.dao.impl.ItemDaoImpl;
import com.tjtt.tdm.codeReview.service.IItemService;
import com.tjtt.tdm.form.bean.AutoFormsField;
import com.tjtt.tdm.form.bean.AutoFormsNew;
import com.tjtt.tdm.form.bean.TdmAnnex;


public class ItemAction extends BaseAction{

	private IItemService itemService;


	public void querySampleByTaskId(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskId = getRequest().getParameter("taskId");
			filterMap.put("taskId", taskId);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_SAMPLENAME","T_SAMPLECOUNT","T_SAMPLENO","T_PICI","T_YINGYONGCHEXING","T_CHEXINGBIANMA","T_MANUFACTURER","T_SONGYANGDATE","T_SAMPLECHULI","FILE_NAME","T_ANNEX"};
			// 查询所有的数据
			PageResult result = itemService.querySampleByTaskId(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//整车样品列表
	public void queryZCSampleByTaskId(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskId = getRequest().getParameter("taskId");
			filterMap.put("taskId", taskId);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_SAMPLENAME","T_SAMPLECOUNT","T_SAMPLENO","T_PICI","T_YINGYONGCHEXING","T_CHEXINGBIANMA","T_MANUFACTURER","T_SONGYANGDATE","T_SAMPLECHULI","FILE_NAME","T_ANNEX"
					,"VIN","CHELIANGXINGHAO","CHENGYUAN","ZHENGBEIZHILIANG","ZUIGAOCHE","LICHENG","DONGLILEIXING","CHELIANGNAME"};
			// 查询所有的数据
			PageResult result = itemService.queryZCSampleByTaskId(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：查询流程中检测项目列表
	 * @author wangxd
	 * @date Jul 3, 2015 3:21:51 PM
	 * @return void
	 * @throw
	 */
	public void queryItemByTaskId(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskId = getRequest().getParameter("taskId");
			String type = getRequest().getParameter("type");
			String flowtaskinfoid = getRequest().getParameter("flowtaskinfoid");
			String stateid  = getRequest().getParameter("stateid"); //常规流程 调度节点：ddshwtd   整车流程 调度节点：proc0
			String itemFlowId = "";
			List flowDetaiList = null;
			//如果是项目分配页面 查询检测项目列表  首先判断调度节点是否从科室任务分配节点退回
			if("ddshwtd".equals(stateid)){ 
				String sql = "select t.id from flow_detailed t where t.flow_task_id="+taskId+" and t.statusbeforeid='ksrwfp' and t.statusafterid='ddshwtd'";
				flowDetaiList = itemService.getDatabySql(sql);
			}
			else if("proc0".equals(stateid)){ 
				String sql = "select t.id from flow_detailed t where t.flow_task_id="+taskId+" and t.statusbeforeid='proc1' and t.statusafterid='proc0'";
				flowDetaiList = itemService.getDatabySql(sql);
			}
			if(null!=flowDetaiList&&flowDetaiList.size()>0){
				String sql ="select wmsys.wm_concat(distinct t.T_ITEMID ) from gwm_item_sample t where t.t_taskid = "+taskId+" and t.t_taskinfoid = "+flowtaskinfoid+"";
				List list = itemService.getDatabySql(sql);
				if(null!=list&&list.size()>0&&null!=list.get(0)){
					itemFlowId = list.get(0).toString();
				}
			}
			filterMap.put("itemFlowId", itemFlowId);
			filterMap.put("taskId", taskId);
			filterMap.put("type", type);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_ITEMNAME","T_BIAOZHUNWEITUO","T_BAOGAOTYPE","T_BGYAOQIU","FILE_NAME","T_ANNEX","bzcount","T_JIANCEMONEY","T_JIANCEBIAOZHUN"};
			// 查询所有的数据
			PageResult result = itemService.queryItemByTaskId(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：选择检测项目的左侧列表
	 * @author wangxd
	 * @date Jul 3, 2015 3:22:04 PM
	 * @return void
	 * @throw
	 */
	public void queryItemFromTable(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String type =  getRequest().getParameter("type");               //0:选择检测项目左侧列表  1：右侧列表
			String deptId = getRequest().getParameter("deptId");              //表单中的检测单位
			String itemName = getRequest().getParameter("itemName");          //检测项目
			String jiancedanwei = getRequest().getParameter("jiancedanwei");  //检测单位
			String danweidaima = getRequest().getParameter("danweidaima");    //单位代码
			String jiancedidian = getRequest().getParameter("jiancedidian");  //检测地点
			String jiancebumen = getRequest().getParameter("jiancebumen");    //检测部门
			String leibie = getRequest().getParameter("leibie");              //检测类别
			String taskId  = getRequest().getParameter("taskId");             //流程ID
			String taskleibie = getRequest().getParameter("taskleibie");
			
			if(!StringUtil.isEmpty(itemName)){
				itemName = StringUtil.encodingUrl(itemName);
			}
			if(!StringUtil.isEmpty(danweidaima)){
				danweidaima = StringUtil.encodingUrl(danweidaima);
			}
			if(!StringUtil.isEmpty(jiancebumen)){
				jiancebumen = StringUtil.encodingUrl(jiancebumen);
			}
			if(!StringUtil.isEmpty(leibie)){
				leibie = StringUtil.encodingUrl(leibie);
			}
			if(!StringUtil.isEmpty(jiancedanwei)){
				jiancedanwei = StringUtil.encodingUrl(jiancedanwei);
			}
			if(!StringUtil.isEmpty(jiancedidian)){
				jiancedidian = StringUtil.encodingUrl(jiancedidian);
			}
			filterMap.put("type", type);
			filterMap.put("deptId", deptId);
			filterMap.put("itemName", itemName);
			filterMap.put("jiancedanwei", jiancedanwei);
			filterMap.put("danweidaima", danweidaima);
			filterMap.put("jiancedidian", jiancedidian);
			filterMap.put("jiancebumen", jiancebumen);
			filterMap.put("leibie", leibie);
			filterMap.put("taskleibie", taskleibie);
			filterMap.put("taskId", taskId);
			
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_ITEMNAME","T_JIANCEDANWEI_NAME","T_JIANCEDANWEI","T_GONGSIDAIMA","T_JIANCEDIDIAN","T_JIANCEBUMEN","T_JIACELEIBIE","T_JIANCEMONEY","T_JIANCEBIAOZHUN"};
			// 查询所有的数据
			PageResult result = itemService.queryItemFromTable(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：查询检测标准
	 * @author wangxd
	 * @date Jul 3, 2015 4:26:47 PM
	 * @return void
	 * @throw
	 */
	public void queryItemBiaozhunByItemId(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String itemId = getRequest().getParameter("itemId");    
			String taskId = getRequest().getParameter("taskId");  
			String jiancebiaozhun =  getRequest().getParameter("jiancebiaozhun");  
			String type =  getRequest().getParameter("type");  //常规检测流程 调度审核委托单 修改检测标准   0：查询左侧的数据
			
			String itemName =  getRequest().getParameter("itemName");    
			String danwei =  getRequest().getParameter("danwei");    
			if(!StringUtil.isEmpty(jiancebiaozhun)){
				jiancebiaozhun = StringUtil.encodingUrl(jiancebiaozhun);
			}
			if(!StringUtil.isEmpty(itemName)){
				itemName = StringUtil.encodingUrl(itemName);
			}
			
			if("0".equals(type)){//常规检测流程--调度审核委托单节点： 修改检测标准
				String sql = "select t.t_itemname,t.t_jiancedanwei from gwm_item t where t.id = "+itemId;
				List list = itemService.getDatabySql(sql);
				if(null!=list&&list.size()>0){
					Object[] objects = (Object[])list.get(0);
					itemName = objects[0]!=null?objects[0].toString():"";
					danwei = objects[1]!=null?objects[1].toString():"";
				}
			}
			filterMap.put("itemId", itemId);
			filterMap.put("taskId", taskId);
			filterMap.put("jiancebiaozhun", jiancebiaozhun);
			filterMap.put("type", type);
			filterMap.put("itemName", itemName);
			filterMap.put("danwei", danwei);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_JIANCEBIAOZHUN","T_JIANCEDANWEI_NAME","T_JIANCEMONEY"};
			
			// 查询所有的数据
			PageResult result = itemService.queryItemBiaozhunByItemId(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：常规检测流程 --调度审核委托单  修改检测标准
	 * @author wangxd
	 * @date Oct 13, 2015 2:35:57 PM
	 * @return void
	 * @throw
	 */
	public void queryOldBiaozhunByItemId(){
		PrintWriter out = PubMethod.GetPrintWriter(); 
		String itemId = getRequest().getParameter("itemId");    
		String taskId = getRequest().getParameter("taskId");  
		String returnValues = "";
		String sql = "select distinct t.t_jiancebiaozhun from gwm_item_flow t where t.t_taskid="+taskId+" and t.t_itemid="+itemId+" and t.t_jiancebiaozhun is not null";
		List list = itemService.getDatabySql(sql);
		if(null!=list&&list.size()>0&&null!=list.get(0)){
			String biaozhun = list.get(0).toString();
			String[] allmsg = biaozhun.split(",");
			for(int i=0;i<allmsg.length;i++){
				returnValues = returnValues+",{ID:'"+i+1+"_t',T_JIANCEBIAOZHUN:'"+allmsg[i]+"'}";
			}
		}
		if(!"".equals(returnValues)){
			returnValues = "["+returnValues.substring(1)+"]";
		}
		out.print(returnValues);
	}
	/**
	 * 保存流程项目中间表
	 * @throws Exception
	 */
	public void saveFlowProject() throws Exception{
		PrintWriter out = getResponse().getWriter();
		try {
			String taskId = getRequest().getParameter("taskId");
			String itemIds = getRequest().getParameter("itemIds");
			itemService.saveFlowProject(itemIds, taskId);
			
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：删除已选的检测项目
	 * @author wangxd
	 * @date Jul 6, 2015 3:31:31 PM
	 * @return void
	 * @throw
	 */
	public void deleteFlowProject() throws Exception{
		PrintWriter out = getResponse().getWriter();
		String itemFlowIds = getRequest().getParameter("itemFlowIds");
		String taskId = getRequest().getParameter("taskId");
		try {
			itemService.deleteFlowProject(taskId,itemFlowIds);
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：保存检测项目列表
	 * @author wangxd
	 * @date Jul 7, 2015 2:44:34 PM
	 * @return void
	 * @throw
	 */
	public void saveItemGrid() throws IOException{
		PrintWriter out = getResponse().getWriter();
		String msg = getRequest().getParameter("msg");
		String flowtaskid = getRequest().getParameter("flowtaskid");
		try {
		    if(!StringUtil.isEmpty(msg)){
		    	msg = StringUtil.encodingUrl(msg);
		    	itemService.saveItemGrid(flowtaskid,msg);
		    }
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：其他检测项目 列表保存
	 * @author wangxd
	 * @date Jul 9, 2015 3:38:19 PM
	 * @return void
	 * @throw
	 */
	public void saveGridOtherItem() throws IOException{
		PrintWriter out = getResponse().getWriter();
		String msg = getRequest().getParameter("msg");
		String flowtaskId = getRequest().getParameter("flowtaskid");
		try {
		    if(!StringUtil.isEmpty(msg)){
		    	msg = StringUtil.encodingUrl(msg);
		    	itemService.saveGridOtherItem(msg, flowtaskId);
		    }
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：其他检测项目中的检测项目存入GWM_ITEM
	 * @author wangxd
	 * @date Jul 7, 2015 5:58:01 PM
	 * @return void
	 * @throw
	 */
	public void saveItemIntoGWMItem() throws IOException{
		PrintWriter out = getResponse().getWriter();
		String itemName = getRequest().getParameter("itemName");
		String deptId = getRequest().getParameter("deptId");
		try {
		    if(!StringUtil.isEmpty(itemName)){
		    	itemName = StringUtil.encodingUrl(itemName);
		    	itemService.saveItemIntoGWMItem(itemName, deptId);
		    }
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：常规检测流程--->项目分配中 样品列表
	 * @author wangxd
	 * @date Jul 14, 2015 4:17:57 PM
	 * @return void
	 * @throw
	 */
	public void queryItemFenpeiSampleno(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String sampleIds = getRequest().getParameter("sampleIds");
			String taskId = getRequest().getParameter("taskId");
			String flowtaskinfoid = getRequest().getParameter("flowtaskinfoid");
			String stateid= getRequest().getParameter("stateid");  //常规检测流程：调度节点：ddshwtd  整车流程：调度节点proc0
			String sampleno = "";
			List flowDetaiList = null;
			if("ddshwtd".equals(stateid)){ 
				String sql = "select t.id from flow_detailed t where t.flow_task_id="+taskId+" and t.statusbeforeid='ksrwfp' and t.statusafterid='ddshwtd'";
				flowDetaiList = itemService.getDatabySql(sql);
			}
			else if("proc0".equals(stateid)){ 
				String sql = "select t.id from flow_detailed t where t.flow_task_id="+taskId+" and t.statusbeforeid='proc1' and t.statusafterid='proc0'";
				flowDetaiList = itemService.getDatabySql(sql);
			}
			if(null!=flowDetaiList&&flowDetaiList.size()>0&&null!=flowDetaiList.get(0)){
				//如果任务是从科室任务分配退回 项目分配中样品显示退回的样品
				String sql = "select distinct t.t_sampleno from gwm_item_sample t where t.t_taskid="+taskId+"  and t.t_taskinfoid="+flowtaskinfoid+" and t.t_sampleno is not null";
				List list = itemService.getDatabySql(sql);
				if(null!=list&&list.size()>0){
					for(int i=0;i<list.size();i++){
						sampleno += ",'"+list.get(i)+"'";
					}
					if(!"".equals(sampleno)){
						sampleno = sampleno.substring(1);
					}
				}
			}
			filterMap.put("sampleno", sampleno);
			filterMap.put("sampleIds", sampleIds);
			filterMap.put("taskId", taskId);
			filterMap.put("flowtaskinfoid", flowtaskinfoid);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_SAMPLENO","T_SAMPLENAME","T_SONGYANGDATE","FILE_NAME","T_ANNEX"};
			// 查询所有的数据
			PageResult result = itemService.queryItemFenpeiSampleno(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：常规检测流程--->项目分配中 项目列表
	 * @author wangxd
	 * @date Jul 14, 2015 4:17:57 PM
	 * @return void
	 * @throw
	 */
	public void queryItemFenpeiItem(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskId = getRequest().getParameter("taskId");
			filterMap.put("taskId", taskId);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_ITEMNAME","JIANCEBIAOZHUN","FILE_NAME","T_ANNEX"};
			// 查询所有的数据
			PageResult result = itemService.queryItemFenpeiItem(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：常规检测流程--->项目分配中 样品/项目列表
	 * @author wangxd
	 * @date Jul 14, 2015 4:17:57 PM
	 * @return void
	 * @throw
	 */
	public  void queryItemSampleByTaskId(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String type =  getRequest().getParameter("type");  //0：调度审核委托单节点 项目分配不显示参数  1：其他节点按照检测参数展开
			String taskId = getRequest().getParameter("taskId");
			String stateId = getRequest().getParameter("stateId");   //流程节点Id
			String flowtaskinfoid = getRequest().getParameter("flowtaskinfoid");
			String reportsftj = getRequest().getParameter("reportsftj");
			
			filterMap.put("type", type);
			filterMap.put("taskId", taskId);
			filterMap.put("stateId", stateId);
			filterMap.put("userId", this.getUserId());
			filterMap.put("flowtaskinfoid", flowtaskinfoid);
			filterMap.put("reportsftj", reportsftj);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_SAMPLENO","T_ITEMNAME","T_JIANCECANSHU","ORG_NAME","T_DEPTLEADERNAME","T_JIACELEIBIE","T_JIANCEBIAOZHUN","T_JIANCEYUANNAME","T_YSJLFILEPATH","T_SFDIANZIQIANM","T_BGFILEPATH","T_BAOGAOTYPE","SAMPLE_FILE_NAME","ITEM_FILE_NAME","ST_ANNEX","IT_ANNEX","MAINID","ISHAVEFILE","T_REPORTSHIBIEH","T_REPORTSFQIANMING","YSJLNAME","BGFILENAME"};
			// 查询所有的数据
			PageResult result = itemService.queryItemSampleByTaskId(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：分配样品、项目、科室领导
	 * @author wangxd
	 * @date Jul 14, 2015 5:50:46 PM
	 * @return void
	 * @throw
	 */
	public void  fenpeiItemAndSample() throws IOException{
		PrintWriter out = getResponse().getWriter();
	  	try {
			String sampleIds =getRequest().getParameter("sampleIds");
			String itemIds =getRequest().getParameter("itemIds");
			String username =getRequest().getParameter("username");
			String userid =getRequest().getParameter("userid");
			String deptId =getRequest().getParameter("deptId");
			String taskId =getRequest().getParameter("taskId");
			String deptName = getRequest().getParameter("deptName");
			String flowtaskinfoid =  getRequest().getParameter("flowtaskinfoid");
			String flag = getRequest().getParameter("flag");//flag=1整车 flag=0常规
			if(!StringUtil.isEmpty(username)){
				username = StringUtil.encodingUrl(username);
			}
			if(!StringUtil.isEmpty(deptName)){
				deptName = StringUtil.encodingUrl(deptName);
			}
			itemService.fenpeiItemAndSample(sampleIds, itemIds, username, userid, deptId, deptName, taskId,flowtaskinfoid,flag);
			out.print("{\"ajaxResult\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"ajaxResult\":\"error\"}");
		}
	}
	/**
	 * 
	 * 描述：删除样品和项目
	 * @author wangxd
	 * @date Jul 15, 2015 11:42:21 AM
	 * @return void
	 * @throw
	 */
	public void deleteGwmItemAndSample() throws Exception{
		PrintWriter out = getResponse().getWriter();
		String ids = getRequest().getParameter("ids");
		String taskId = getRequest().getParameter("taskId");
		try {
			itemService.deleteGwmItemAndSample(ids,taskId);
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	
	/**
	 * 分配人员
	 * author:lishu	 2014-3-11
	 * @throws IOException 
	 */
	public void fenpeiUser() throws IOException{
		PrintWriter out = getResponse().getWriter(); 
		try {
			String deptId = this.getDeptid();
			String ids = getRequest().getParameter("ids");
			String userId = getRequest().getParameter("userid");
			String taskInfoId = getRequest().getParameter("taskInfoId");
			itemService.fenpeiUser(ids, userId,taskInfoId);
			String output = "{\"ajaxResult\":\"success\"}";
			out.print(output);
		} catch (Exception e) {
			e.printStackTrace();
			String output = "{\"ajaxResult\":\"error\"}";
			out.print(output);
		}
	}
	/**
	 * 清除人员
	 * author:lishu	 2014-3-11
	 * @throws IOException 
	 */
	public void deleteUser() throws IOException{
		PrintWriter out =  getResponse().getWriter();
		try {
			String ids = getRequest().getParameter("ids");
			String taskInfoId = getRequest().getParameter("taskInfoId");
			itemService.deleteUser(ids,taskInfoId);
			String output = "{\"ajaxResult\":\"success\"}";
			out.print(output);
		} catch (Exception e) {
			e.printStackTrace();
			String output = "{\"ajaxResult\":\"error\"}";
			out.print(output);
		}
	}
	
	public void queryDeptUsers()throws IOException{
		setContentType();
		PrintWriter out =  getResponse().getWriter();
		try {
			String deptid = getRequest().getParameter("deptid");
			String output = itemService.queryDeptUsers(deptid);
			out.print(output);
		} catch (Exception e) {
			e.printStackTrace();
			String output = "{\"ajaxResult\":\"error\"}";
			out.print(output);
		}
	}
	/**
	 * 
	 * 描述：常规检测流程  调度审核委托单 修改检测标准
	 * @author wangxd
	 * @date Jul 24, 2015 9:27:56 AM
	 * @return void
	 * @throws IOException 
	 * @throw
	 */
	public void updateItemBiaozhun() throws IOException{
		PrintWriter out =  getResponse().getWriter();
		try {
			String itemId = getRequest().getParameter("itemId");
			String taskId = getRequest().getParameter("taskId");
			String biaozhun = getRequest().getParameter("biaozhun");
			String jiancemoney = getRequest().getParameter("jiancemoney");
			if(!StringUtil.isEmpty(biaozhun)){
				biaozhun = StringUtil.encodingUrl(biaozhun);
			}
		    itemService.updateItemBiaozhun(itemId, taskId,biaozhun,jiancemoney);
			String output = "{\"ajaxResult\":\"success\"}";
			out.print(output);
		} catch (Exception e) {
			e.printStackTrace();
			String output = "{\"ajaxResult\":\"error\"}";
			out.print(output);
		}
	}
	/**
	 * 我的请求---检测项目
	 * wxj
	 * @return
	 */
	public void queryMyItemSample(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskId = getRequest().getParameter("taskId");
			filterMap.put("taskId", taskId);
			String flowtypeid = getRequest().getParameter("flowtypeid");
			//将查询条件保存到Map里
			String[] viewArray = { "filepath","leibieno","shibiehao","t_itemname","t_taskid","t_jianceyuanname","ID"};
			PageResult result = null;
			// 查询所有的数据
			if(null != flowtypeid && !"".equals(flowtypeid) && "2241".equals(flowtypeid)){//研发
				result = itemService.queryMyItemSampleYF(filterMap);
			}else{//常规和整车
				result = itemService.queryMyItemSample(filterMap);
			}
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：查询检测项目列表
	 * @author wangxd
	 * @date Sep 24, 2015 8:39:49 AM
	 * @return void
	 * @throw
	 */
	public void queryGwmItemList(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String itemname = getRequest().getParameter("T_ITEMNAME");
			String danwei = getRequest().getParameter("T_JIANCEDANWEI");
			String didian = getRequest().getParameter("T_JIANCEDIDIAN");
			String bumen = getRequest().getParameter("T_JIANCEBUMEN");
			String leibie = getRequest().getParameter("T_JIACELEIBIE");
			
			if(!StringUtil.isEmpty(itemname)){
				itemname = StringUtil.encodingUrl(itemname);
			}
			if(!StringUtil.isEmpty(danwei)){
				danwei = StringUtil.encodingUrl(danwei);
			}
			if(!StringUtil.isEmpty(didian)){
				didian = StringUtil.encodingUrl(didian);
			}
			if(!StringUtil.isEmpty(bumen)){
				bumen = StringUtil.encodingUrl(bumen);
			}
			if(!StringUtil.isEmpty(leibie)){
				leibie = StringUtil.encodingUrl(leibie);
			}
			filterMap.put("itemname", itemname);
			filterMap.put("danwei", danwei);
			filterMap.put("didian", didian);
			filterMap.put("bumen", bumen);
			filterMap.put("leibie", leibie);
			//将查询条件保存到Map里
			String[] viewArray = {"T_ITEMNAME","T_JIANCEDANWEI_NAME","T_JIANCEDANWEI","T_GONGSIDAIMA","T_JIANCEDIDIAN","T_JIANCEBUMEN","T_JIACELEIBIE","ID"};
			// 查询所有的数据
			PageResult result = itemService.queryGwmItemList(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：检测项目列表删除功能
	 * @author wangxd
	 * @date Sep 24, 2015 2:21:48 PM
	 * @return void
	 * @throw
	 */
	public void deleteGwmItem() throws IOException{
		String ids = getRequest().getParameter("ids");
		String flag = getRequest().getParameter("flag");  //0:删除检测项目 1：删除检测标准
		PrintWriter out = getResponse().getWriter();
		try {
			itemService.deleteGwmItem(ids,flag);
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	/**
	 * 
	 * 描述：修改检测项目、检测标准
	 * @author wangxd
	 * @date Sep 24, 2015 5:30:15 PM
	 * @return String
	 * @throw
	 */
	public String updateGwmItemById(){
//		String id = getRequest().getParameter("id");              //检测项目ID
//		String biaozhunId = getRequest().getParameter("biaozhunId");  //检测标准ID
		String itemName = getRequest().getParameter("itemName");   //检测项目
		String jiancedanwei = getRequest().getParameter("danwei");   //检测单位
		String jiancebiaozhun = getRequest().getParameter("biaozun");
		String jiancebumen = getRequest().getParameter("bumen");   //检测部门
		String jianceleibie = getRequest().getParameter("leibie"); //检测类别
		
		String flag =  getRequest().getParameter("flag"); //0：修改检测项目 1：修改检测标准
		
		String danweidaima = "" ;    //单位代码
		String jiancedidian = "";    //检测地点
		String jiancefeiyong = "";   //检测费用
		String jiancedanweiName = "";  //检测单位名称
		
		if(!StringUtil.isEmpty(itemName)){
			itemName = StringUtil.encodingUrl(itemName);
		}
		if(!StringUtil.isEmpty(jiancedanwei)){
			jiancedanwei = StringUtil.encodingUrl(jiancedanwei);
		}
		if(!StringUtil.isEmpty(jiancebiaozhun)){
			jiancebiaozhun = StringUtil.encodingUrl(jiancebiaozhun);
		}
		
		if(!StringUtil.isEmpty(jiancebumen)){
			jiancebumen = StringUtil.encodingUrl(jiancebumen);
		}
		
		if(!StringUtil.isEmpty(jianceleibie)){
			jianceleibie = StringUtil.encodingUrl(jianceleibie);
		}
		String sql = "select t.t_gongsidaima,t.t_jiancedidian,t.t_jiancebiaozhun,t.t_jiancemoney,t.t_jiancedanwei_name from gwm_item t where t.t_itemname='"+itemName+"' and t.t_jiancedanwei='"+jiancedanwei+"' and t.t_jiancebumen ='"+jiancebumen+"' and t.t_jiaceleibie='"+jianceleibie+"'";
		
		if("1".equals(flag)){
			sql += " and t.t_jiancebiaozhun ='"+jiancebiaozhun+"'";
		}
		List list = itemService.getDatabySql(sql);
		if(null!=list&&list.size()>0&&null!=list.get(0)){
			Object[] obj = (Object[])list.get(0);
			danweidaima = obj[0]!=null?obj[0].toString():"";
			jiancedidian = obj[1]!=null?obj[1].toString():"";
			jiancebiaozhun = obj[2]!=null?obj[2].toString():"";
			jiancefeiyong = obj[3]!=null?obj[3].toString():"";
			jiancedanweiName = obj[4]!=null?obj[4].toString():"";
		}
		
		getRequest().setAttribute("itemName", itemName);
		getRequest().setAttribute("jiancedanwei", jiancedanwei);
		getRequest().setAttribute("danweidaima", danweidaima);
		getRequest().setAttribute("jiancedidian", jiancedidian);
		getRequest().setAttribute("jiancebumen", jiancebumen);
		getRequest().setAttribute("jianceleibie", jianceleibie);
		getRequest().setAttribute("jiancebiaozhun", jiancebiaozhun);
		getRequest().setAttribute("jiancefeiyong", jiancefeiyong);
		getRequest().setAttribute("jiancedanweiName", jiancedanweiName);
		getRequest().setAttribute("flag", flag);
		
		return "updateItem";
	}
	/**
	 * 
	 * 描述：删除原始记录
	 * @author wangxd
	 * @date Oct 11, 2015 12:41:07 PM
	 * @return void
	 * @throw
	 */
	public void delYsjl() throws IOException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
	  	try {
	  		String ids=getRequest().getParameter("ids");
	  		itemService.delYsjl(ids);
			out.print("{\"ajaxResult\":\"success\"}");
	  	} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"ajaxResult\":\"error\"}");
		}
	}
	
	/**
	 * 
	 * 描述：原始记录节点删除 检测标准
	 * @author wangxd
	 * @date Oct 13, 2015 9:43:46 PM
	 * @return void
	 * @throw
	 */
	public void updateJiancecanshu() throws IOException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		try {
			String flag = getRequest().getParameter("flag");  //0：删除检测标准  1:恢复检测标准
			String ids=getRequest().getParameter("ids");
			itemService.deleteJiancecanshu(flag,ids);
			out.print("{\"ajaxResult\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"ajaxResult\":\"error\"}");
		}
	}
	
	/**
	 * 
	 * 描述：查询已删除的检测参数列表
	 * @author wangxd
	 * @date Oct 13, 2015 10:20:31 PM
	 * @return void
	 * @throw
	 */
	public void queryJiancecanshuList(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String taskInfoId = getRequest().getParameter("taskInfoId");
			filterMap.put("taskInfoId", taskInfoId);
			//将查询条件保存到Map里
			String[] viewArray = { "ID","T_SAMPLENO","T_ITEMNAME","T_JIANCECANSHU","ORG_NAME","T_DEPTLEADERNAME","T_JIACELEIBIE","T_JIANCEBIAOZHUN","T_JIANCEYUANNAME"};
			// 查询所有的数据
			PageResult result = itemService.queryJiancecanshuList(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void queryItemcanshuList(){
		try {
			//取出页面中的查询条件
			Map<String, String> filterMap = getPagerMap();
			String itemname = getRequest().getParameter("itemname");
			String danwei = getRequest().getParameter("danwei");
			String leibie = getRequest().getParameter("leibie");
			if(!StringUtil.isEmpty(itemname)){
				itemname = StringUtil.encodingUrl(itemname);
			}
			if(!StringUtil.isEmpty(leibie)){
				leibie = StringUtil.encodingUrl(leibie);
			}
			filterMap.put("itemname", itemname);
			filterMap.put("danwei", danwei);
			filterMap.put("leibie", leibie);
			//将查询条件保存到Map里
			String[] viewArray = { "ROWNUM","T_ITEMNAME","T_JIANCEDANWEI","T_JIACELEIBIE","T_JIANCECANSHU"};
			// 查询所有的数据
			PageResult result = itemService.queryItemcanshuList(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 描述：检测项目管理----添加参数、修改参数
	 * @author wangxd
	 * @date Oct 15, 2015 9:33:32 PM
	 * @return void
	 * @throw
	 */
	public void saveItemCanshu() throws IOException{
		PrintWriter out = getResponse().getWriter();
		try{
			String itemname = getRequest().getParameter("itemname");
			String danwei = getRequest().getParameter("danwei");
			String leibie = getRequest().getParameter("leibie");
			String canshu = getRequest().getParameter("T_JIANCECANSHU");
			String oldcanshu  = getRequest().getParameter("oldcanshu");  //修改页面 原检测参数
			String flag =  getRequest().getParameter("flag");  //0：添加 1：修改
			if(!StringUtil.isEmpty(itemname)){
				itemname = StringUtil.encodingUrl(itemname);
			}
			if(!StringUtil.isEmpty(leibie)){
				leibie = StringUtil.encodingUrl(leibie);
			}
			if(!StringUtil.isEmpty(oldcanshu)){
				oldcanshu = StringUtil.encodingUrl(oldcanshu);
			}
			
			if("0".equals(flag)){
				String querySql =" select t_jiancebumen, t_gongsidaima, t_jiancedidian,t_jiancemoney,t_jiancebiaozhun,t_jiancebumen_id , t_jiancedanwei_name from gwm_item t  where t.t_itemname='"+itemname+"' and t.t_jiancedanwei='"+danwei+"' and t.t_jiaceleibie='"+leibie+"' ";
				List list= itemService.getDatabySql(querySql);
				if(null!=list&&list.size()>0&&null!=list.get(0)){
					Object[] objects = (Object[])list.get(0);
					String t_jiancebumen = objects[0]!=null?objects[0].toString():"";
					String t_gongsidaima = objects[1]!=null?objects[1].toString():"";
					String t_jiancedidian = objects[2]!=null?objects[2].toString():"";
					String t_jiancemoney = objects[3]!=null?objects[3].toString():"";
					String t_jiancebiaozhun = objects[4]!=null?objects[4].toString():"";
					Long t_jiancebumen_id = objects[5]!=null?Long.parseLong(objects[5].toString()):null;
					String t_jiancedanwei_name = objects[6]!=null?objects[6].toString():"";
					String insertSql = "insert into gwm_item " +
			        "(id,t_jiancecanshu, t_jiancebumen, t_gongsidaima, t_jiancedidian, t_jiaceleibie, t_itemname, t_jiancedanwei, t_jiancemoney, t_jiancebiaozhun, t_jiancebumen_id, t_jiancedanwei_name) values  " +
			        "(SEQ_GWM_ITEM.NEXTVAL,'"+canshu+"','"+t_jiancebumen+"','"+t_gongsidaima+"','"+ t_jiancedidian+"','"+ leibie+"','"+itemname+"','"+danwei+"','"+ t_jiancemoney+"','',"+t_jiancebumen_id+",'"+ t_jiancedanwei_name+"')";
			        itemService.executeSql(insertSql);
				}
			}
			else{
				if(!canshu.equals(oldcanshu)){
					String updateSql ="update gwm_item t set t.t_jiancecanshu='"+canshu+"' where t.t_itemname='"+itemname+"' and t.t_jiancedanwei='"+danwei+"' and t.t_jiaceleibie='"+leibie+"' and t.t_jiancecanshu ='"+oldcanshu+"' ";
				    itemService.executeSql(updateSql);
				}
				
			}
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
		
	}
	
	/**
	 * 
	 * 描述：检测项目管理---- 删除检测参数
	 * @author wangxd
	 * @date Oct 15, 2015 9:34:32 PM
	 * @return void
	 * @throw
	 */
	public void deleteGwmItemCanshu() throws IOException{
		PrintWriter out = getResponse().getWriter();
		try{
			String itemname = getRequest().getParameter("itemname");
			String danwei = getRequest().getParameter("danwei");
			String leibie = getRequest().getParameter("leibie");
			String canshu = getRequest().getParameter("canshu");
			if(!StringUtil.isEmpty(itemname)){
				itemname = StringUtil.encodingUrl(itemname);
			}
			if(!StringUtil.isEmpty(leibie)){
				leibie = StringUtil.encodingUrl(leibie);
			}
			if(!StringUtil.isEmpty(canshu)){
				canshu = StringUtil.encodingUrl(canshu);
			}
			itemService.deleteGwmItemCanshu(itemname, danwei, leibie, canshu);
			
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
		
	}
	public IItemService getItemService() {
		return itemService;
	}

	public void setItemService(IItemService itemService) {
		this.itemService = itemService;
	}
	
	
}
